<template>

    <layout :title="information.title">
        <mt-header fixed title="资讯详情">
            <a href="javascript:window.history.go(-1);" slot="left">
                <mt-button  icon="back"></mt-button>
            </a>
        </mt-header>

        <div class="txte_box" v-html="">
            {{ information.title }}
        </div>

        <div class="text_title" v-html="information.content"></div>
        <div class="top_ft">
            <div class="top_l" v-if="" style="margin-bottom: 1rem">{{ information.commentCount}}评论 {{ information.clickRate}}浏览</div>
            <!--<div class="top_l" v-else="">{{ information.commentCount}}评论 {{ information.clickRate}}浏览</div>-->
        </div>

        <div class="page-infinite-wrapper" ref="wrapper" :style="{ height: wrapperHeight + 'px' }">
            <ul class="ui_list page-infinite-list" v-infinite-scroll="loadMore" infinite-scroll-disabled="loading" infinite-scroll-distance="50">
                <li class="item" v-for="item in list">
                    <div class="list_img">
                        <div class="list_l">
                            <img :src="api.image + item.headImgUrl"/>
                        </div>
                        <div class="list_r">
                            <span>{{item.commentPersonName}}</span>
                            <span>{{item.createDate}}</span>

                        </div>
                    </div>

                    <div class="list_c">{{item.content}}</div>

                    <div class="list_f">
                        <a :href="'/information/comment/'+item.id" class="list_f_l" v-if="item.reviewCount == 0">回复</a>
                        <a :href="'/information/comment/'+item.id" class="list_f_l" v-else>查看{{item.reviewCount}}条回复</a>
                    </div>
                </li>
            </ul>
            <p v-show="loading" class="page-infinite-loading">
                <mt-spinner :size="20" type="fading-circle"></mt-spinner>
                <span>加载中...</span>
            </p>
            <div class="footer">
            <span >
                	<input type="text" v-model="content" placeholder="开始你的评价">
                	<span class="sumint" @click="comment">发送</span>

                </span>
            </div>

        </div>
    </layout>
</template>
<style lang="scss">
    @import "index";

    .mint-header{
        color: #181818;
        background: #FFFFFF;
        border-bottom: 0.01rem solid #DDDDDD;
    }

    .txte_box{
        box-sizing: border-box;
        margin-top: 1rem;
        height: auto;
        padding: 0rem 0.24rem;

    }
</style>
<script type="text/babel">
    import { api, image } from 'framework/config.js';
    import Layout from "component/layout/standard";

    import Vue from 'vue'
    import Mint from 'mint-ui';
    Vue.use(Mint);

    export default {
        components: {
            Layout
        },
        data(){
            return {
                content: '',
                selected: '1',
                list: [],
                lastPage: false,
                pageNo: 0,
                nextPage: 1,
                sort: 0,
                type: '',
                loading: false,
                wrapperHeight: 0
            }
        },
        computed: {
            api(){
                return api();
            }
        },
        methods: {
            showImage(url, params){
                return image(this.api.image, url, params);
            },
            reload(){
                this.list = [];
                this.nextPage = 1;
                this.pageNo = 1;
                this.lastPage = false;
                this.loadMore();
            },
            loadMore(){
                if (this.lastPage){
                    return;
                }
                this.loading = true;
                this.$http.get('/api/comment/list', {
                    params: {
                        id: this.information.id,
                        pageNo: this.nextPage
                    }
                }).then((response) => {
                    if (response.status == 200){
                        let data = response.data;
                        if (data.code == 200) {
                            data = data.data;
                            this.lastPage = data.lastPage;
                            this.pageNo = data.pageNo;
                            this.nextPage = data.nextPage;

                            let list = data.list;
                            for (let i = 0; i < list.length; i++){
                                this.list.push(list[i]);
                            }

                        }

                    }else{
                        this.lastPage = true;
                    }
                    this.loading = false;
                })
            },
            comment(){
                let param = new URLSearchParams();
                param.append("type", 1);
                param.append("id", this.information.id);
                param.append("content", this.content);

                this.$http.post('/api/comment/information/add',
                    param
                ).then((response) => {
                    if (response.status == 200){
                        let data = response.data;
                        if (data.code == 200) {
                            this.content = '';
                            this.reload();
                        }
                    }else{
                    }
                })
            }
        },
        created(){
        },
        mounted() {
            this.wrapperHeight = document.documentElement.clientHeight - this.$refs.wrapper.getBoundingClientRect().top;
        }
    }
</script>

